define(function(require, exports, module) {

	// 定义Cookie
	var cookie = require("cookie");

	require("json");

	var userSetting = getSetting();

	var init = function() {
		//userSetting.mini = false;
		//saveSetting(userSetting);
		//===========读取cookie初始化设置=============
		//导航悬浮
		if (userSetting.navbar) {
			$(".navbar").addClass("navbar-fixed-top");
			$("body").addClass("navbar-fixed");
			$("#settingDialog input[value='1']").prop("checked", true);
		} else {
			$(".navbar").removeClass("navbar-fixed-top");
			$("body").removeClass("navbar-fixed");
			$("#settingDialog input[value='1']").prop("checked", false);
		}
		//左侧菜单悬浮
		if (userSetting.menu) {
			$(".page_sidebar").addClass("sidebar_fixed");
			$("#settingDialog input[value='2']").prop("checked", true);
		} else {
			$(".page_sidebar").removeClass("sidebar_fixed");
			$("#settingDialog input[value='2']").prop("checked", false);
		}
		//面包屑悬浮
		if (userSetting.breadcrumb) {
			$(".breadcrumb").addClass("breadcrumb_fixed");
			$(".container_shadow").addClass("container_fixed");
			$("#settingDialog input[value='3']").prop("checked", true);
		} else {
			$(".breadcrumb").removeClass("breadcrumb_fixed");
			$(".container_shadow").removeClass("container_fixed");
			$("#settingDialog input[value='3']").prop("checked", false);
		}
		//窄屏
		if (userSetting.container) {
			//"body").addClass("container");
			$(".container_shadow").addClass("container");
			$(".page_header").addClass("container");
			$("#settingDialog input[value='4']").prop("checked", true);
		} else {
			//"body").removeClass("container");
			$(".container_shadow").removeClass("container");
			$(".page_header").removeClass("container");
			$("#settingDialog input[value='4']").prop("checked", false);
		}
		$(".container_shadow:before").width($(".container_shadow").width() + 1);
	}

	var setting = function() {
		userSetting = getSetting();

		//导航悬浮
		if ($("#settingDialog input[value='1']").prop("checked")) {
			$(".navbar").addClass("navbar-fixed-top");
			$("body").addClass("navbar-fixed");
			userSetting.navbar = true;
		} else {
			$(".navbar").removeClass("navbar-fixed-top");
			$("body").removeClass("navbar-fixed");
			userSetting.navbar = false;
		}
		//左侧菜单悬浮
		if ($("#settingDialog input[value='2']").prop("checked")) {
			$(".page_sidebar").addClass("sidebar_fixed");
			userSetting.menu = true;
		} else {
			$(".page_sidebar").removeClass("sidebar_fixed");
			userSetting.menu = false;
		}
		//面包屑悬浮
		if ($("#settingDialog input[value='3']").prop("checked")) {
			$(".breadcrumb").addClass("breadcrumb_fixed");
			$(".container_shadow").addClass("container_fixed");
			userSetting.breadcrumb = true;
		} else {
			$(".breadcrumb").removeClass("breadcrumb_fixed");
			$(".container_shadow").removeClass("container_fixed");
			userSetting.breadcrumb = false;
		} //窄屏
		if ($("#settingDialog input[value='4']").prop("checked")) {
			//$("body").addClass("container");
			$(".container_shadow").addClass("container");
			$(".page_header").addClass("container");
			userSetting.container = true;
		} else {
			//$("body").removeClass("container");
			$(".container_shadow").removeClass("container");
			$(".page_header").removeClass("container");
			userSetting.container = false;
		}
		saveSetting(userSetting);
	}

	//保存设置
	var saveSetting = function(setting) {
		if (window.localStorage) {
			window.localStorage.setItem("userSetting", JSON.stringify(setting));
		} else {
			cookie("userSetting", JSON.stringify(setting));
		}
	}

	// 获取设置
	function getSetting() {
		if (window.localStorage) {
			return window.localStorage.getItem("userSetting") ? $.parseJSON(window.localStorage.getItem("userSetting")) : new Object();
		} else {
			return cookie("userSetting") ? $.parseJSON(cookie("userSetting")) : new Object();
		}
	}

	return {
		init: init,
		setting: setting,
		saveSetting: saveSetting,
		getSetting: getSetting
	}
});